<!DOCTYPE html>
<html>

<head>
    <title>游记列表</title>
    <meta charset="utf-8"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <link rel="stylesheet" href="/js/bootstrap-4.1.1-dist/css/bootstrap.min.css">
    <script src="/js/jquery/jquery.min.js"></script>
    <script src="/js/bootstrap-4.1.1-dist/js/bootstrap.min.js"></script>
    <link rel="stylesheet" href="/css/font/css/font-awesome.min.css">
    <link rel="stylesheet" href="/css/reset.css"/>
    <link rel="stylesheet" href="/css/travel.css"/>
    <script src="/js/plugins/jrender/jrender.min.js"></script>
    <link rel="stylesheet" href="/js/plugins/dialog2/dialog.css">
    <script src="/js/plugins/dialog2/dialog.min.js"></script>
    <script src="/js/common.js"></script>

    <script>
        $(function () {
            //定义全局变量获取搜索框内容
            var search;
            $("#searchBtn").val('');
            //给搜索框绑定点击事件
            $("#searchBtn").click(function () {
                //获取搜索框的内容
                search=$(this).val();
            });

            //给搜索按钮绑定点击事件
            $("#buttonSearch").click(function () {
                //调用点击事件
                $("#searchBtn").click();
                console.log(search);
                if (search){
                    $.ajax({
                        url:baseUrl+"/travels/{search}",
                        type:'post',
                        data:{search:search},
                        success:function (data) {
                            console.log(data);
                            //将除搜索外的所有标签全部隐藏起来
                            $(".recommendTravel").attr("hidden",true);
                            $(".travelAll").attr("hidden",true);
                            //将隐藏的div解除隐藏
                            $(".travelHidden").attr("hidden",false);
                            //对div进行数据渲染
                            $(".travelHidden").renderValues(data,{
                                getHref:getHref,
                                getSearchTravel:getHref
                            });
                            $(".search-head a").attr("href","");
                        }
                    });
                }
            })






            //获取每月推荐的游记
            $.get(baseUrl + "/travelCommends/2", function (data) {
                console.log(data);
                $("#carouselExampleControls").renderValues(data, {
                    getHref: getHref
                });
                $(".carousel-item:first").addClass("active");
            });
            showComments("carousel-inner");
            var currentPage = 1;//定义当前页,默认为1
            var arr = [];//定义一个数组,用来装所有的分页数据
            var totalPage;//定义总页数
            var loading = false;//判断是否真正加载数据
            function query() {
                if (loading == true) {
                    return;
                }
                loading = true;
                $.get(baseUrl + "/travels", {currentPage: currentPage}, function (data) {
                    console.log(data);
                    totalPage = data.pages;
                    //合并数据
                    $.merge(arr, data.list);
                    //改变数据格式
                    var json = {list: arr};
                    // 使用jrender 插件渲染数据 到页面
                    $("#allTravels").renderValues(json, {
                        getHref: getHref
                    });
                    currentPage++;
                    loading = false;
                });
            };
            query();
            $(window).scroll(function () {
                if ($(window).height() + $(document).scrollTop() >= $(document).height()) {
                    if (currentPage <= totalPage) {
                        query();
                    } else {
                        $(document).dialog({
                            type: 'notice',
                            infoText: '已经到底啦',
                            autoClose: 2500,
                            position: 'bottom'  // center: 居中; bottom: 底部
                        });
                    }
                }
            });

            //浏览量
        /*    $("#travelTitle").click(function () {
                console.log("哈哈");
                var viewNum = $("#pageView").html();
               viewNum++;
                $("#pageView").html(viewNum);
            })*/

        //查询浏览量
          /*  $.get(baseUrl+"/travels"+"/selectViews",function (data) {
                $(".pageView").renderValues(data);
            })*/

        })

   /*     function ds(){
            var viewNum = $("#pageView").html();
            viewNum++;
            var travelId = $("#travelId").html()
            $.post(baseUrl+"/travels"+"/addViews",{pageView:viewNum,id:travelId},function (data) {
                $("#pageView").html(data);
            })
        }*/

    </script>

</head>

<body style="background: url('/upload/2.bmp')">

<div class="search-head" style="background: url('/upload/2.bmp')">
    <div class="row nav-search">
        <div class="col-1">
            <a href="index.html">
                <span><i class="fa fa-chevron-left fa-2x"></i></span>
            </a>
        </div>
        <div class="col-10">
            <div class="input-group-sm search">
                <input class="form-control" id="searchBtn" placeholder="搜游记">
            </div>
            <a href="#">
                <i class="fa fa-search" id="buttonSearch"
                   style="color:white;font-size:25px;position: absolute;top: 23%;left: 92%">
                </i>
            </a>
        </div>
        <div class="col-1">
            <!--<button class="btn" id="buttonSearch">搜索</button>-->
        </div>
    </div>
</div>

<!--定义隐藏的div作为搜索结果-->
<div class="container travelHidden" hidden>
    <h6>相关游记</h6>
    <div id="searchTravels">
        <div render-loop="list">
            <div class="row detail">
                <div class="col">
                    <a data-url="travelContent.html?id=" render-fun="getHref" render-key="list.id">
                        <h4 render-html="list.title"> 骨灰级成都吃货地图1</h4>
                    </a>
                    <p>
                        <a data-url="userProfiles.html?id=" render-fun="getHref" render-key="list.author.id">
                            <img class="rounded-circle head-img" render-src="list.author.headImgUrl">
                            <span render-html="list.author.nickName">喵喵</span> </a> 在
                        <span class="addr" render-html="list.place.name">成都</span>

                    </p>
                 <!--   <p>
                        <i class="fa fa-eye fa-fw"></i>
                        <span>0</span>
                        <i class="fa fa-commenting fa-fw"></i>
                        <span>0</span>
                    </p>-->
                </div>
                <div class="col bigimg">
                    <a data-url="travelContent.html?id=" render-fun="getSearchTravel" render-key="list.id">
                        <img render-src="list.coverUrl">
                    </a>
                </div>
            </div>
        </div>
    </div>
</div>
<hr>
<div class="container recommendTravel">

    <h6>每月冠军游记</h6>
    <div id="carouselExampleControls" class="carousel slide" data-ride="carousel">
        <div>
            <div id="travelsCommends" class="carousel-inner" render-loop="list">
                <div class="carousel-item">
                    <div class="border commend">
                        <a data-url="travelContent.html?id=" render-fun="getHref" render-key="list.travelId">
                            <img render-src="list.coverUrl">
                            <h1 render-html="list.title"> 骨灰级成都吃货地图</h1>
                            <small render-html="list.regionName">成都成都</small>
                        </a>
                    </div>
                </div>
            </div>
        </div>

        <a class="carousel-control-prev" href="#carouselExampleControls" role="button" data-slide="prev">
            <span class="carousel-control-prev-icon" aria-hidden="true"></span>
            <span class="sr-only"></span>
        </a>
        <a class="carousel-control-next" href="#carouselExampleControls" role="button" data-slide="next">
            <span class="carousel-control-next-icon" aria-hidden="true"></span>
            <span class="sr-only"></span>
        </a>
    </div>
</div>

<div class="container travelAll">
    <h6>全部游记</h6>
    <div id="allTravels">
        <div render-loop="list">
            <div class="row detail">
                <div class="col">
                    <a data-url="travelContent.html?id=" render-fun="getHref" render-key="list.id">
                        <span hidden render-html="list.id" id="travelId"></span>
                        <h4 render-html="list.title" onclick="ds()"> 骨灰级成都吃货地图1</h4>
                    </a>
                    <p>
                        <a data-url="userProfiles.html?id=" render-fun="getHref" render-key="list.author.id">
                            <img class="rounded-circle head-img" render-src="list.author.headImgUrl">
                            <span render-html="list.author.nickName">喵喵</span> </a> 在
                        <span class="addr" render-html="list.place.name">成都</span>

                    </p>

                    <p>
                        <span></span>
                        <!--   <i class="fa fa-eye fa-fw"></i>
                         <span id="pageView">0</span>
                         <div class="pageView">
                         <div render-loop="list">
                         </div>
                          </div>
                        <i class="fa fa-commenting fa-fw"></i>
                        <span id="pageComment">0</span>
                        -->
                    </p>

                </div>
                <div class="col bigimg">
                    <a data-url="travelContent.html?id=" render-fun="getHref" render-key="list.id">
                        <img render-src="list.coverUrl">
                    </a>
                </div>
            </div>
        </div>
    </div>
</div>


</body>

</html>